<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  <meta name="renderer" content="webkit">

  
  <title>Android系统模块编译调试与Ninja使用指南 | 龙之叶的博客</title>

  <link rel="shortcut icon" href="/images/favicon.png">
  <link rel="alternate" href="/atom.xml" title="龙之叶的博客" type="application/atom+xml">
  <meta name="description" content="Android系统模块编译调试与Ninja使用指南">
<meta property="og:type" content="article">
<meta property="og:title" content="Android系统模块编译调试与Ninja使用指南">
<meta property="og:url" content="http://longzhiye.top/2025/06/29/2025-06-29/index.html">
<meta property="og:site_name" content="龙之叶的博客">
<meta property="og:description" content="Android系统模块编译调试与Ninja使用指南">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2025-06-28T16:00:00.000Z">
<meta property="article:modified_time" content="2025-07-10T07:34:18.692Z">
<meta property="article:author" content="龙之叶">
<meta property="article:tag" content="Android">
<meta property="article:tag" content="framework">
<meta property="article:tag" content="build">
<meta name="twitter:card" content="summary">

  <meta name="keywords" content=",Android,framework,build">
  <meta name="format-detection" content="telephone=no,email=no">
  <meta name="theme-color" content="#9C27B0">

  <meta name="mobile-web-app-capable" content="yes">
  <meta name="application-name" content="龙之叶的博客">
  <meta name="msapplication-starturl" content="http://longzhiye.top/2025/06/29/2025-06-29/">
  <meta name="msapplication-navbutton-color" content="#9C27B0">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-title" content="龙之叶的博客">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon" href="/images/favicon.png">

  
    <link rel="canonical" href="http://longzhiye.top/2025/06/29/2025-06-29/">
  

  
  

  
  
  

  
<link rel="stylesheet" href="/css/mdui.css">
<link rel="stylesheet" href="/css/style.css">

  
<link rel="stylesheet" href="/custom.css">

<meta name="generator" content="Hexo 5.4.2"></head>

<body class="mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink">
  <script>var a=localStorage.getItem("mdui-theme-layout-dark");if(a){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>var a=localStorage.getItem("mdui-drawer-close");if(!a){document.getElementsByTagName("body")[0].className+=" mdui-drawer-body-left"};</script>
  <header id="header" class="mdui-appbar mdui-appbar-fixed mdui-appbar-scroll-hide mdui-appbar-inset">
  <div class="mdui-toolbar mdui-color-theme">
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-drawer="{target: '#sidebar', swipe: true}"><i class="mdui-icon material-icons">menu</i></a>
    <a href="/" class="mdui-typo-headline">龙之叶的博客</a>
    <div class="mdui-toolbar-spacer"></div>
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-dialog="{target: '#search'}" mdui-tooltip="{content: '搜索'}"><i class="mdui-icon material-icons">search</i></a>
	<!--
    <a href="/atom.xml" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'RSS'}"><i class="mdui-icon material-icons">rss_feed</i></a>
	-->
  </div>
</header>
<div class="mdui-dialog" id="search">
  
    <div class="search-form">
      <input type="search" class="search-form-input" placeholder="请输入关键字">
    </div>
    <div class="search-result" data-resource="/search.xml"></div>
  
</div>

  <aside id="sidebar" class="mdui-drawer mdui-drawer-full-height">
  <script>var a=localStorage.getItem("mdui-drawer-close");if(a){document.getElementById("sidebar").className+=" mdui-drawer-close"};</script>
  <div class="mdui-grid-tile">
    <img src="/images/banner.png" style="height: 160px;">
    <img src="/images/avatar.png" class="avatar-animation" style="position: absolute; top: 10%; left: 24px; width: 64px; height: 64px; border: 2px solid #fff; border-radius: 50%;background-color:#fff;">
    <div class="mdui-grid-tile-actions">
      <div class="mdui-grid-tile-text">
        <div class="mdui-grid-tile-title">龙之叶</div>
        <div class="mdui-grid-tile-subtitle"><i class="mdui-icon material-icons">art_track</i>生命不息，折腾不止</div>
      </div>
      
        <div class="mdui-grid-tile-buttons">
          <a href="mailto:longzhiye163@163.com" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'longzhiye163@163.com'}"><i class="mdui-icon material-icons">email</i></a>
        </div>
      
    </div>
  </div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    <a href="/" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-blue">home</i>
      <div class="mdui-list-item-content">主页</div>
    </a>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-0");if(a){document.getElementsByClassName("mdui-collapse-item")[0].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-deep-orange">archive</i>
        <div class="mdui-list-item-content">归档</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/archives/2025/07/">七月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/06/">六月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/03/">三月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/02/">二月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/01/">一月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/10/">十月 2024<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/09/">九月 2024<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/08/">八月 2024<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/03/">三月 2024<span class="mdui-ripple sidebar_archives-count">5</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/02/">二月 2024<span class="mdui-ripple sidebar_archives-count">11</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/01/">一月 2024<span class="mdui-ripple sidebar_archives-count">9</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/12/">十二月 2023<span class="mdui-ripple sidebar_archives-count">10</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/11/">十一月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/10/">十月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/09/">九月 2023<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/08/">八月 2023<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/06/">六月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/05/">五月 2023<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/04/">四月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/03/">三月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/02/">二月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/09/">九月 2022<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/08/">八月 2022<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/04/">四月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/03/">三月 2017<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/02/">二月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/01/">一月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/12/">十二月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/11/">十一月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/10/">十月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/08/">八月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-1");if(a){document.getElementsByClassName("mdui-collapse-item")[1].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-green">class</i>
        <div class="mdui-list-item-content">分类</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术<span class="mdui-ripple sidebar_archives-count">98</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E7%94%9F%E6%B4%BB/">生活<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E8%B5%84%E8%AE%AF/">资讯<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E9%80%9A%E7%9F%A5/">通知<span class="mdui-ripple sidebar_archives-count">4</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-2");if(a){document.getElementsByClassName("mdui-collapse-item")[2].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-brown">bookmark</i>
        <div class="mdui-list-item-content">标签</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/tags/ANR/" rel="tag">ANR<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/APP/" rel="tag">APP<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android/" rel="tag">Android<span class="mdui-ripple sidebar_archives-count">89</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android12/" rel="tag">Android12<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android13/" rel="tag">Android13<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android14/" rel="tag">Android14<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AndroidStudio/" rel="tag">AndroidStudio<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AutoDraw/" rel="tag">AutoDraw<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Crash/" rel="tag">Crash<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Foxmail/" rel="tag">Foxmail<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Framework/" rel="tag">Framework<span class="mdui-ripple sidebar_archives-count">20</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GPS%E8%BD%A8%E8%BF%B9%E5%9B%BE/" rel="tag">GPS轨迹图<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Git/" rel="tag">Git<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GitHub/" rel="tag">GitHub<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Google/" rel="tag">Google<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Hexo/" rel="tag">Hexo<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Java/" rel="tag">Java<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Kernel/" rel="tag">Kernel<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Launcher/" rel="tag">Launcher<span class="mdui-ripple sidebar_archives-count">17</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Lib/" rel="tag">Lib<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Linux/" rel="tag">Linux<span class="mdui-ripple sidebar_archives-count">18</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Markdown/" rel="tag">Markdown<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Material-Design/" rel="tag">Material Design<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OS-X/" rel="tag">OS X<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OTA/" rel="tag">OTA<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/QuickTime/" rel="tag">QuickTime<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SSH/" rel="tag">SSH<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Settings/" rel="tag">Settings<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SystemUI/" rel="tag">SystemUI<span class="mdui-ripple sidebar_archives-count">19</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Ubuntu/" rel="tag">Ubuntu<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WPS/" rel="tag">WPS<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Wifi/" rel="tag">Wifi<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WindTerm/" rel="tag">WindTerm<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Windows/" rel="tag">Windows<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/androidmk/" rel="tag">androidmk<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/blog/" rel="tag">blog<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/build/" rel="tag">build<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/feel/" rel="tag">feel<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/framework/" rel="tag">framework<span class="mdui-ripple sidebar_archives-count">50</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/git/" rel="tag">git<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/inotify/" rel="tag">inotify<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/life/" rel="tag">life<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/ninja/" rel="tag">ninja<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/rsync/" rel="tag">rsync<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/standard/" rel="tag">standard<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/test/" rel="tag">test<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1/" rel="tag">企业微信<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag">操作系统<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E7%94%9F%E6%B4%BB%E6%84%9F%E6%82%9F/" rel="tag">生活感悟<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <a href="/about" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-purple">person</i>
      <div class="mdui-list-item-content">关于</div>
    </a>
  </div>

  <div class="mdui-divider"></div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    
      <a href="/timeline" class="mdui-list-item mdui-ripple">时间轴</a>
    
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-3");if(a){document.getElementsByClassName("mdui-collapse-item")[3].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <div class="mdui-list-item-content">友情链接</div>
        <i class="mdui-list-item-icon mdui-icon material-icons">link</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
          <a href="http://www.niemingzhao.top" target="_blank" class="mdui-list-item mdui-p-l-2 mdui-text-color-theme-accent mdui-ripple" style="justify-content: center;">聂明照的博客</a>
        
        
      </div>
    </div>
  </div>
</aside>

  <main id="main" class="mdui-m-t-5 fadeIn animated">
  
<link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">

  <style>#main article .mdui-card-content .center-block{display:block!important;margin-right:auto!important;margin-left:auto!important}</style>
  <style>#main article .mdui-card-content .text-center{text-align:center!important}</style>
  <article class="mdui-card mdui-m-b-5">
    <header class="mdui-card-media">
      <img src="/images/random/material-8.png" style="max-height: 240px;">
      <div class="mdui-card-media-covered">
        <div class="mdui-card-primary">
          <div class="mdui-card-primary-title">Android系统模块编译调试与Ninja使用指南</div>
          <div class="mdui-card-primary-subtitle"><i class="iconfont">&#xe697;</i> 2025-06-29 / <i class="iconfont">&#xe601;</i> 龙之叶 &nbsp;&nbsp; <span id="busuanzi_container_page_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_page_pv"></span></span></div>
        </div>
      </div>
      <div class="mdui-card-menu">
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#qrcode', align: 'right'}"><i class="mdui-icon material-icons">devices</i></button>
          <ul class="mdui-menu" id="qrcode">
            
              <li class="mdui-menu-item"><a class="mdui-text-center mdui-ripple">发送到手机</a></li>
            
            <li class="mdui-menu-item" disabled>
              
                <img src="//qr.liantu.com/api.php?w=246&m=10&text=http://longzhiye.top/2025/06/29/2025-06-29/">
              
            </li>
          </ul>
        
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#share_menu', align: 'right'}"><i class="mdui-icon material-icons">share</i></button>
          <ul class="mdui-menu" id="share_menu">
            <li class="mdui-menu-item">
              <a href="https://service.weibo.com/share/share.php?appkey=&title=Android系统模块编译调试与Ninja使用指南&url=http://longzhiye.top/2025/06/29/2025-06-29/&pic=http://longzhiye.top/images/favicon.png&searchPic=false&style=simple" target="_blank" class="mdui-ripple">分享到 Weibo</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://twitter.com/intent/tweet?text=Android系统模块编译调试与Ninja使用指南&url=http://longzhiye.top/2025/06/29/2025-06-29/&via=龙之叶" target="_blank" class="mdui-ripple">分享到 Twitter</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.facebook.com/sharer/sharer.php?u=http://longzhiye.top/2025/06/29/2025-06-29/" target="_blank" class="mdui-ripple">分享到 Facebook</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://plus.google.com/share?url=http://longzhiye.top/2025/06/29/2025-06-29/" target="_blank" class="mdui-ripple">分享到 Google+</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.linkedin.com/shareArticle?mini=true&url=http://longzhiye.top/2025/06/29/2025-06-29/&title=Android系统模块编译调试与Ninja使用指南" target="_blank" class="mdui-ripple">分享到 LinkedIn</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://connect.qq.com/widget/shareqq/index.html?site=龙之叶的博客&title=Android系统模块编译调试与Ninja使用指南&pics=http://longzhiye.top/images/favicon.png&url=http://longzhiye.top/2025/06/29/2025-06-29/" target="_blank" class="mdui-ripple">分享到 QQ</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://telegram.me/share/url?url=http://longzhiye.top/2025/06/29/2025-06-29/&text=Android系统模块编译调试与Ninja使用指南" target="_blank" class="mdui-ripple">分享到 Telegram</a>
            </li>
          </ul>
        
      </div>
    </header>
    <div class="mdui-card-content mdui-typo">
      <h2 id="模块编译调试方法"><a href="#模块编译调试方法" class="headerlink" title="模块编译调试方法"></a>模块编译调试方法</h2><p>(此处举例framework、installd、SystemUI等模块的编译调试，其他类似)</p>
<h3 id="1-Framework模块编译"><a href="#1-Framework模块编译" class="headerlink" title="1. Framework模块编译"></a>1. Framework模块编译</h3><p>Android系统代码的framework目录内，一共有3个模块单独编译：framework、services、framework-res.apk。</p>
<p><strong>注意</strong>：偶尔会有改了代码但没检测到，编译结束后产物并未更新的情况，所以可以考虑先剪切掉原先的产物或者检查产物更新时间确保已经重新编译。</p>
<p><strong>步骤</strong>：</p>
<ol>
<li>完成根目录下 <code>source build/envsetup.sh</code> 命令、<code>lunch qssi-userdebug-mars</code> 命令（准备好编译环境、选择好编译分支，才可以开始编译）。</li>
<li>整编命令如 <code>bash build.sh -j32 dist --qssi_only 2&gt;&amp;1 | tee buildlog.log</code>。</li>
</ol>
<h4 id="1-1-修改frameworks-base-core-res下的内容"><a href="#1-1-修改frameworks-base-core-res下的内容" class="headerlink" title="1.1 修改frameworks/base/core/res下的内容"></a>1.1 修改frameworks/base/core/res下的内容</h4><ul>
<li>在执行 <code>source build/envsetup.sh</code> 命令的版本源代码根目录执行 <code>make framework-res -j32</code>。</li>
<li>产物位于 <code>out/target/product/qssi/system/framework</code> 下面（如 <code>framework-res.apk</code> 之类），push到手机的 <code>/system/framework/</code> 下面重启即可。</li>
</ul>
<h4 id="1-2-修改framework-base-services下的内容"><a href="#1-2-修改framework-base-services下的内容" class="headerlink" title="1.2 修改framework/base/services下的内容"></a>1.2 修改framework/base/services下的内容</h4><ul>
<li>在执行 <code>source build/envsetup.sh</code> 命令的版本源代码根目录执行 <code>make services -j32</code>。</li>
<li>产物位于 <code>out/target/product/qssi/system/framework</code> 下面，拿出来push到手机的 <code>/system/framework/</code> 下面重启即可。</li>
</ul>
<h4 id="1-3-修改framework-base-core下的内容"><a href="#1-3-修改framework-base-core下的内容" class="headerlink" title="1.3 修改framework/base/core下的内容"></a>1.3 修改framework/base/core下的内容</h4><ul>
<li>在执行 <code>source build/envsetup.sh</code> 命令的版本源代码根目录执行 <code>make framework-minus-apex -j32</code>。</li>
<li>产物位于 <code>out/target/product/qssi/system/framework</code> 下面，拿出来push到手机的 <code>/system/framework/</code> 下面重启即可。</li>
<li><strong>问题处理</strong>：如果卡在开机过程里（常在小于Android13版本中发生），而且不是自己原因导致而是一些AndroidRuntime错误导致的signal 6的内存错误，可尝试在push <code>framework.jar</code> 后 <code>adb shell rm -rf system/framework/oat system/framework/arm system/framework/arm64</code> 再重启。</li>
</ul>
<h4 id="1-4-其他目录下的代码修改"><a href="#1-4-其他目录下的代码修改" class="headerlink" title="1.4 其他目录下的代码修改"></a>1.4 其他目录下的代码修改</h4><ul>
<li>在framework/base下的其他很多目录下的代码修改也可以被编译到，但需要自行确认：<ul>
<li>故意改错去编译。</li>
<li>搜Android.bp文件内容看看framework-minus-apex library的srcs是否包含了被修改的文件。</li>
</ul>
</li>
</ul>
<h4 id="1-5-作SDK"><a href="#1-5-作SDK" class="headerlink" title="1.5 作SDK"></a>1.5 作SDK</h4><ul>
<li>如果是要make出jar包给apk调用而不是push到系统里调试，那要拿此目录的jar包：<code>out/target/common/obj/JAVA_LIBRARIES/framework-minus-apex_intermediates/classes.jar</code>。</li>
<li><strong>版本改动注意</strong>：在Android11之前修改了framework相关代码，只需 <code>make framework</code> 就可以编译出 <code>framework.jar</code>。在Android11，这个编译命令不起作用了，根据framework/base/目录下Android.bp中的提示，编译命令需要改为 <code>make framework-minus-apex</code>。</li>
</ul>
<h3 id="2-修改frameworks-native-cmds-abcd的任意模块代码"><a href="#2-修改frameworks-native-cmds-abcd的任意模块代码" class="headerlink" title="2. 修改frameworks/native/cmds/abcd的任意模块代码"></a>2. 修改frameworks/native/cmds/abcd的任意模块代码</h3><ul>
<li>通过 <code>make abcd -j32</code> 编译，比如 <code>make installd -j16</code> <code>make atrace -j16</code> 等。</li>
<li>产物位于 <code>out/target/product/qssi/system/bin</code> 下面，拿出来push到手机的 <code>/system/bin/</code> 下面重启即可。</li>
</ul>
<h3 id="3-修改packages-modules-abcd的代码"><a href="#3-修改packages-modules-abcd的代码" class="headerlink" title="3. 修改packages/modules/abcd的代码"></a>3. 修改packages/modules/abcd的代码</h3><ul>
<li>通过找被修改文件属于的同/上级目录的Android.bp文件中哪个模块内编译，在此模块library中找到apex_available标签，即标识该library可以被name为xxxx的apex包进去，通过 <code>make xxxx -j32</code> 编译。</li>
<li>产物位于 <code>out/target/product/qssi/system/apex/</code> 下面，拿出来push到手机的 <code>/system/apex/</code> 下面重启即可。</li>
<li><strong>示例</strong>：修改了 <code>/packages/modules/Wifi/framework/java/android/net/wifi/WifiManager.java</code>，那么在 <code>/packages/modules/Wifi/framework/Android.bp</code> 中找到 <code>apex_available: [&quot;com.android.wifi&quot;, &quot;test_com.android.wifi&quot;]</code>，就知道 <code>make com.android.wifi -j16</code> 可以编译到被修改文件。</li>
</ul>
<h3 id="4-改动SystemUI、Settings等模块的代码"><a href="#4-改动SystemUI、Settings等模块的代码" class="headerlink" title="4. 改动SystemUI、Settings等模块的代码"></a>4. 改动SystemUI、Settings等模块的代码</h3><ul>
<li>可以通过 <code>make SystemUI</code>、<code>make Settings</code> 来进行编译，产物在 <code>/system/app</code> 或 <code>/system/priv-app</code> 下面，将结果apk直接install，然后重启此应用相关服务，如直接重启手机，或者如SystemUI在install后 <code>adb shell am restart</code> 也可以。</li>
<li><strong>注意</strong>：不要push已经存在的apk到手机，重启系统不会扫描，新的apk不会重新安装，测试效果将还是原先的效果，除非此系统apk可以先删掉重启再push再重启。</li>
</ul>
<h3 id="5-通用编译模块的方法"><a href="#5-通用编译模块的方法" class="headerlink" title="5. 通用编译模块的方法"></a>5. 通用编译模块的方法</h3><ul>
<li>如修改位于 <code>framework/native/services</code> 下的文件，可以通过在同级或上级目录中的Android.bp文件内容中查找修改的文件名字或具体目录，来找到所属sources，再逐级向上找到被编译进哪个“name”的目标产物xxx中，再 <code>make xxx -j32</code> 对其编译。</li>
<li>如果xxx编译出的产物是中间产物或手机中没有的无法替换的产物可以再向上查找更大name的目标产物xxxx（如：cc_library_shared、cc_library、java_library、apex_available等）进行编译或直接push进system/lib和system/lib64重启。</li>
</ul>
<h3 id="6-编译system-img"><a href="#6-编译system-img" class="headerlink" title="6. 编译system.img"></a>6. 编译system.img</h3><ul>
<li>当你确定修改的内容能在编译system.img时带入，可以使用 <code>make systemimage -j16</code> 编译。通过进入fastboot模式后刷system.img进行生效。</li>
</ul>
<h3 id="编译调试注意点"><a href="#编译调试注意点" class="headerlink" title="编译调试注意点"></a>编译调试注意点</h3><ol>
<li>编译最好把已经生成的先删掉，不然有可能文件不更新（push前check下文件的生成时间）。</li>
<li>编译终端最后提示的生成路径不一定是唯一生成路径，同级目录、对称lib或lib64目录里可能都有你需要的生成物。library要把生成的库文件在system/lib和system/lib64下都做相应的push。</li>
<li>如果是push替换库文件，最好留一个原本的备份避免push了开不了机器。</li>
<li>编译调试的时候如果是自己陌生的模块，建议每次都加行特殊log以确认自己的修改已经生效。</li>
</ol>
<h2 id="二、使用ninja替代make进行快速编译"><a href="#二、使用ninja替代make进行快速编译" class="headerlink" title="二、使用ninja替代make进行快速编译"></a>二、使用ninja替代make进行快速编译</h2><h3 id="为什么要使用ninja？"><a href="#为什么要使用ninja？" class="headerlink" title="为什么要使用ninja？"></a>为什么要使用ninja？</h3><p>通常使用make编译会有两个阶段：</p>
<ol>
<li>先分析Android.bp，将所有需要参与编译的文件的路径都记录下，writing build rules并打包到 <code>out/soong/combined-.ninja</code> 中。（普遍耗时15-20min）</li>
<li>然后ninja工具通过第一步生成的文件，编译要编译的模块。（不同模块速度不同，比如services模块只需要大约20s）</li>
</ol>
<p><strong>优点</strong>：直接使用ninja就可以省去第一部分耗时，尤其在反复编译时调试效率提高。</p>
<h3 id="注意点"><a href="#注意点" class="headerlink" title="注意点"></a>注意点</h3><ol>
<li>进行ninja之前必须要先make一次（当然要想make必须先根目录source和lunch一次），以生成路径文件；如果你的修改增删了模块中文件的名字路径，就必须重新make生成路径文件。</li>
</ol>
<h3 id="ninja的获取"><a href="#ninja的获取" class="headerlink" title="ninja的获取"></a>ninja的获取</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span>到android系统源码的根目录下，执行</span><br><span class="line"><span class="built_in">cp</span> prebuilts/build-tools/linux-x86/bin/ninja out/host/linux-x86/bin/</span><br><span class="line"><span class="built_in">cp</span> prebuilts/build-tools/linux-x86/bin/ninja /usr/local/bin/</span><br><span class="line"><span class="built_in">cp</span> prebuilts/build-tools/linux-x86/bin/ninja /usr/bin/</span><br><span class="line"><span class="built_in">ln</span> -sf out/combined-***.ninja build.ninja</span><br></pre></td></tr></table></figure>

<h3 id="ninja文件内容"><a href="#ninja文件内容" class="headerlink" title="ninja文件内容"></a>ninja文件内容</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"><span class="function"><span class="title">ninja</span></span>()&#123;</span><br><span class="line"> ninja_bin=<span class="string">&quot;<span class="variable">$ANDROID_BUILD_TOP</span>/prebuilts/build-tools/linux-x86/bin/ninja&quot;</span></span><br><span class="line"> ninja_build_file=<span class="string">&quot;<span class="variable">$ANDROID_BUILD_TOP</span>/out/combined-<span class="variable">$TARGET_PRODUCT</span>.ninja&quot;</span></span><br><span class="line"> <span class="keyword">if</span> [ ! -f <span class="variable">$ninja_build_file</span> ]</span><br><span class="line"> <span class="keyword">then</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">&quot;can&#x27;t find ninja buildfile <span class="variable">$ninja_build_file</span>&quot;</span></span><br><span class="line"> <span class="built_in">exit</span> -1</span><br><span class="line"> <span class="keyword">fi</span></span><br><span class="line"> <span class="keyword">if</span> [ ! -f <span class="variable">$ninja_bin</span> ]</span><br><span class="line"> <span class="keyword">then</span></span><br><span class="line"> <span class="built_in">echo</span> <span class="string">&quot;can&#x27;t find ninja binary <span class="variable">$ninja_bin</span>&quot;</span></span><br><span class="line"> <span class="built_in">exit</span> -1</span><br><span class="line"> <span class="keyword">fi</span></span><br><span class="line"> <span class="variable">$ninja_bin</span> -f <span class="variable">$ninja_build_file</span> <span class="variable">$1</span></span><br><span class="line"> &#125;</span><br><span class="line"><span class="comment">#usage:ninja&lt;modulename&gt;</span></span><br><span class="line">ninja $*</span><br></pre></td></tr></table></figure>

<h3 id="ninja的执行"><a href="#ninja的执行" class="headerlink" title="ninja的执行"></a>ninja的执行</h3><p>如果执行ninja进行快速编译时，遇到如下错误：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ninja: error <span class="keyword">while</span> loading shared libraries: libjemalloc5.so: cannot open shared object file: No such file or directory</span><br></pre></td></tr></table></figure>

<p>使用如下解决方法：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo <span class="built_in">cp</span> prebuilts/build-tools/linux-x86/lib64/libjemalloc5.so /usr/lib</span><br></pre></td></tr></table></figure>

      
      <blockquote>
        
        <strong>本文链接：</strong><br><a href="http://longzhiye.top/2025/06/29/2025-06-29/">http://longzhiye.top/2025/06/29/2025-06-29/</a>
      </blockquote>
    </div>
    <footer class="mdui-card-actions">
      
        <a class="mdui-ripple article_categories-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术</a>
      
      
        <a class="mdui-ripple article_tags-link" href="/tags/Android/" rel="tag">Android</a><a class="mdui-ripple article_tags-link" href="/tags/build/" rel="tag">build</a><a class="mdui-ripple article_tags-link" href="/tags/framework/" rel="tag">framework</a>
      
    </footer>
    
  </article>
  
<script src="//cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

  <script>$("#main article .mdui-card-content img.fancybox").on("click",function(e){$.fancybox.open({src:$(this).attr("src")});});</script>


  <nav id="paginator">
    
      <a rel="prev" class="extend prev" href="/2025/07/06/2025-07-06/">
        <button aria-label="prev" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_back</i></button>
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Git Commit 生成与合入 Patch 指南'}">上一篇</span>
      </a>
    
    <div class="spacer"></div>
    
      <a rel="next" class="extend next" href="/2025/06/28/2025-06-28/">
        <span class="mdui-p-x-3" mdui-tooltip="{content: '展锐平台(Android15)WLAN热点名称修改不生效问题分析'}">下一篇</span>
        <button aria-label="next" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_forward</i></button>
      </a>
    
  </nav>





</main>
  <footer id="footer" class="mdui-m-t-5 mdui-p-y-3 mdui-color-theme">
  <div class="mdui-p-y-0 mdui-text-center">
    
    
    
    
    
    
    
      <a href="http://github.com/longzhiye" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe7ab;</i></a>
    
    
    
      <a href="https://www.zhihu.com/people/long-zhi-xie-61" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe6c0;</i></a>
    
    
    
      <a href="tencent://tencent:////message/?uin=951898105&Menu=yes" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe651;</i></a>
    
    
  </div>
  <div class="mdui-p-y-1 mdui-text-center">
    Copyright &copy; 2022 - 2025 龙之叶<br>
    Powered by <a href="https://hexo.io/" target="_blank" class="mdui-text-color-theme-accent">Hexo</a>
    <br>
      <span id="busuanzi_container_site_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_site_pv"></span></span> &nbsp;&nbsp;
      <span id="busuanzi_container_site_uv" style="display: none;"><i class="iconfont">&#xe601;</i> <span id="busuanzi_value_site_uv"></span></span>
    
  </div>
</footer>

  <button id="gotop" class="mdui-fab mdui-fab-fixed mdui-fab-hide mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_upward</i></button>
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  
<script src="/js/mdui.js"></script>
<script src="/js/script.js"></script>

  
<script src="/custom.js"></script>

</body>
</html>
